/**
 * @class   wosh::gui::LayoutStandard
 * @brief   
 *          
 *          
 *
 ****************************************************************************
 * @version $Id: LayoutStandard.h 2887 2010-08-11 08:09:41Z alex $
 * @author  Alessandro Polo
 ****************************************************************************/
/* Copyright (c) 2007-2010, WOSH - Wide Open Smart Home 
 * by Alessandro Polo - OpenSmartHome.com
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *     * Redistributions of source code must retain the above copyright
 *       notice, this list of conditions and the following disclaimer.
 *     * Redistributions in binary form must reproduce the above copyright
 *       notice, this list of conditions and the following disclaimer in the
 *       documentation and/or other materials provided with the distribution.
 *     * Neither the name of the OpenSmartHome.com WOSH nor the
 *       names of its contributors may be used to endorse or promote products
 *       derived from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY Alessandro Polo ''AS IS'' AND ANY
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL Alessandro Polo BE LIABLE FOR ANY
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 ****************************************************************************/
 
#ifndef __WOSH_Gui_LayoutStandard_H__
 #define __WOSH_Gui_LayoutStandard_H__

#include <framework/gui/kiosk/Navigator.h>
#include <framework/gui/kiosk/KioskLayout.h>

#include <QtGui/QGraphicsWidget>
#include <QtGui/QGraphicsScene>
#include <QtGui/QGraphicsLinearLayout>

namespace wosh {
 namespace gui {


class GadgetsContainer : public QGraphicsWidget  {

	Q_OBJECT

	public:
		GadgetsContainer();
		virtual ~GadgetsContainer() { }

	public:
		void addGadget( QGraphicsWidget* item );

	Q_SIGNALS:
		void gadgetMaximize( QGraphicsWidget* item );
		void gadgetMinimize( QGraphicsWidget* item );

	protected:
		QGraphicsLinearLayout* layout;
};

////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////

class LayerOpaque : public QObject, public QGraphicsRectItem  {

	Q_OBJECT
	Q_PROPERTY(QRectF rect READ rect WRITE setRect)
#if QT_VERSION >= 0x040600
	Q_PROPERTY(qreal opacity READ opacity WRITE setOpacity)
#endif

	public:
		LayerOpaque();
		virtual ~LayerOpaque() { }

	public:
		void init();
		void showLayer( bool visible, bool opaque_n_animation = true );

	protected:
		virtual void mousePressEvent( QGraphicsSceneMouseEvent *  ) { }
		virtual void mouseReleaseEvent( QGraphicsSceneMouseEvent *  ) { }
		virtual void mouseDoubleClickEvent( QGraphicsSceneMouseEvent *  ) { }
		virtual void keyPressEvent( QKeyEvent *  ) { }
		virtual void keyReleaseEvent( QKeyEvent *  ) { }
		virtual void hoverEnterEvent( QGraphicsSceneHoverEvent *  ) { }
		virtual void hoverLeaveEvent( QGraphicsSceneHoverEvent *  ) { }
		virtual void hoverMoveEvent( QGraphicsSceneHoverEvent *  ) { }
		virtual void contextMenuEvent( QGraphicsSceneContextMenuEvent *  ) { }
		virtual void dragEnterEvent( QGraphicsSceneDragDropEvent *  ) { }
		virtual void dragLeaveEvent( QGraphicsSceneDragDropEvent *  ) { }
		virtual void dragMoveEvent( QGraphicsSceneDragDropEvent *  ) { }
		virtual void dropEvent( QGraphicsSceneDragDropEvent *  ) { }
		virtual void wheelEvent( QGraphicsSceneWheelEvent *  ) { }
};

////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////

class LayerModalProxy : public QGraphicsProxyWidget {

	Q_OBJECT

	public:
		LayerModalProxy();
		virtual ~LayerModalProxy() { }

	public:
		void configureFor( QWidget* widget );
};

////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////

class LayoutStandard : public QObject, public KioskLayout  {

	Q_OBJECT

	public:
		LayoutStandard();
		virtual ~LayoutStandard() { }

	public:
		void init();

	public slots:

		virtual void showModal( QWidget* panel );
		virtual void hideModal();

		virtual void maximize_sheet( bool value );

		bool maximize( QGraphicsWidget* item );
		//void request_restore();

	protected slots:
		void navigator_itemSelected( NavigatorItem* item );

	public:
		virtual void setSheet( QGraphicsWidget* item );
		virtual void addGadget( QGraphicsWidget* item );

		virtual void blockInput( bool add_opaque_layer = false );

	public:
		Navigator* getNavigator()				{ return this->navigator; }
		QGraphicsWidget* getSheetCurrent()		{ return this->sheetCurrent; }
		GadgetsContainer* getGadgetsContainer()	{ return this->gadgetsContainer; }

		LayerOpaque* getItemLayerOpaque()		{ return this->itemLayerOpaque; }
		LayerModalProxy* getItemModalProxy()	{ return this->itemModalProxy; }

		virtual void setNavigatorListener( INavigatorListener* listener );

	public:
		QGraphicsScene* getScene()				{ return this->scene; }
		int getHeight()							{ return (int)this->scene->height(); }
		int getWidth()							{ return (int)this->scene->width(); }

	protected:
		QGraphicsScene* scene;

		QGraphicsWidget* sheetCurrent;
		Navigator* navigator;
		GadgetsContainer* gadgetsContainer;

		int navigatorHeight;
		int gadgetWidth;

	protected:
		LayerOpaque* itemLayerOpaque;
		LayerModalProxy* itemModalProxy;

	protected:
		INavigatorListener* navListener;

};

  }; // namespace gui
}; // namespace wosh

#endif // __WOSH_Gui_LayoutStandard_H__
